package com.shiyingzi.auser.service.impl;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.shiyingzi.auser.dao.AChannelDao;
import com.shiyingzi.auser.model.AChannel;
import com.shiyingzi.auser.service.AChannelService;
import com.shiyingzi.common.EntityUtils;
import com.shiyingzi.common.PageUtils;
import com.shiyingzi.common.PageableData;
import com.shiyingzi.common.ResponseData;


@Service(AChannelService.BEAN_ID)
public class AChannelServiceImpl extends ServiceImpl<AChannelDao,AChannel> implements AChannelService{
	@Autowired
	private AChannelDao aChannelDao;
	@Autowired
	private HttpSession session;
	@Override
	public ResponseData addAChannel(AChannel code) {
		try{
			code.setDeleteFlag("N");
			code.setChState("1");
			EntityUtils.initEntity(code, session);
			aChannelDao.insert(code);
			return new ResponseData(true,"true",code);
		}catch(Exception e){
			return new ResponseData(false,"false");
		}
	}

	@Override
	public PageableData<AChannel> queryAChannelList(int page, int limit,
			String chName) {		
		Page<AChannel> mypage = new Page<AChannel>();
		mypage.setCurrent(page);
		mypage.setSize(limit);
		AChannel ac =new AChannel();
		if(!StringUtils.isEmpty(chName)){
			ac.setChName(chName);
		}
		
		return PageUtils.tableDataDto(selectPage(mypage,new EntityWrapper<AChannel>(ac).orderBy("createTime")));
	}

	@Override
	public ResponseData updateAChannel(AChannel code) {
		try{
			EntityUtils.modifyEntity(code, session);
			
			return new ResponseData(true,"true",updateAChannel(code));
		}catch(Exception e){
			return new ResponseData(false,"false");
		}
	}

	@Override
	public List<AChannel> findlistBystate() {
		List<AChannel> list=aChannelDao.selectList(new EntityWrapper<AChannel>().eq("ch_state", 1));
		return list;
	}

	@Override
	public AChannel getAChannelById(Integer id) {
		AChannel code=getAChannelById(id);
		return code;
	}

	@Override
	public List<AChannel> findAllList() {
		List<AChannel> list=selectList(null);
		return list;
	}

}
